package cn.tannn.tconfig.client.config;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 客户端配置中心环境配置
 *
 * @author <a href="https://tannn.cn/">tnnn</a>
 * @version V1.0
 * @date 2024/5/4 下午7:23
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ConfigMeta {

    /**
     * 应用
     */
    private String app;
    /**
     * 环境
     */
    private String env;
    /**
     * namespace
     */
    private String ns;
    /**
     * 配置中心地址 {e.g http://localhost:9129}
     */
    private String configServer;



    public String genKey() {
        return this.getApp() + "_" + this.getEnv() + "_" + this.getNs();
    }

    public String listPath() {
        return path("list");
    }

    public String versionPath() {
        return path("version");
    }


    private String path(String context) {
        return this.getConfigServer() + "/configs/" + context + "?app=" + this.getApp()
                + "&env=" + this.getEnv() + "&ns=" + this.getNs();
    }
}
